from DBA.dbmanager import DBInterface

class AccessPoint:
	
	def __init__(self,id=""):
		self.id			= {"key":"ID","value":id}
		self.name		= {"key":"nom","value":""}
		self.essid		= {"key":"essid","value":""}
		self.macaddress		= {"key":"mac","value":""}
		self.xposition		= {"key":"x","value":""}
		self.yposition		= {"key":"y","value":""}
		self.zposition		= {"key":"z","value":""}
		self.mobile		= {"key":"mobile","value":""}
		self.cryptage		= {"key":"cryptage","value":""}
		self.dhcp		= {"key":"dhcp","value":""}
		self.geodescription	= {"key":"geodescription","value":""}
		self.__interfacebase	= DBInterface()
		if not id:
			self.id["value"]	= str(self.__interfacebase.createNewID());
	

	def createByDico(self,dico):
		self.name["value"] 		= dico[self.name["key"]]
		self.essid["value"] 		= dico[self.essid["key"]]
		self.macaddress["value"] 	= dico[self.macaddress["key"]]
		self.xposition["value"] 	= dico[self.xposition["key"]]
		self.yposition["value"] 	= dico[self.yposition["key"]]
		self.zposition["value"] 	= dico[self.zposition["key"]]
		self.mobile["value"] 		= dico[self.mobile["key"]]
		self.cryptage["value"] 		= dico[self.cryptage["key"]]
		self.dhcp["value"] 		= dico[self.dhcp["key"]]
		self.geodescription["value"] 	= dico[self.geodescription["key"]]

	def insertToDb(self,idSalle):
		dico = self.createAccessPointDico(idSalle)
		self.__interfacebase.insert(self.__interfacebase.accessPointtablename,self.__interfacebase.accessPointmapping,dico)
	
	def updateIntoDb(self,idSalle):
		dico = self.createAccessPointDico(idSalle)
		self.__interfacebase.update(self.__interfacebase.accessPointtablename,self.__interfacebase.accessPointmapping,dico)
	
	def createAccessPointDico(self,idSalle):
		dico ={}
		dico[self.id["key"]]		= self.id["value"]
		dico["link_sa"]			= idSalle
		dico[self.name["key"]]		= self.name["value"]
		dico[self.essid["key"]]		= self.essid["value"]
		dico[self.macaddress["key"]]	= self.macaddress["value"]
		dico[self.xposition["key"]]	= self.xposition["value"]
		dico[self.yposition["key"]]	= self.yposition["value"]
		dico[self.zposition["key"]]	= self.zposition["value"]
		dico[self.mobile["key"]]	= self.mobile["value"]
		dico[self.cryptage["key"]]	= self.cryptage["value"]
		dico[self.dhcp["key"]]		= self.dhcp["value"]
		dico[self.geodescription["key"]]= self.geodescription["value"]
		return dico

if __name__=="__main__":
	bat = Batiment()
	bat.name["value"]		= "test";
	bat.description["value"]	= "Description du batiment";
	bat.xposition["value"]		= "34";
	bat.yposition["value"]		= "23";
	bat.zposition["value"]		= "15";
	bat.height["value"]		= "123";
	bat.width["value"]		= "23";
	
	from SalleModule import Salle
	sal = Salle()
	sal.name["value"]		= "salle 1";
	#sal.description["value"]	= "Description";
	sal.xposition["value"]		= "12";
	sal.yposition["value"]		= "12";
	sal.zposition["value"]		= "12";
	sal.height["value"]		= "432";
	sal.width["value"]		= "234";
	bat.addSalle(sal)
	bat.insertToDb();
